package com.smz.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.smz.entity.SCompany;
import com.smz.service.SCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class SCompanyController {

    @Autowired
    private SCompanyService sCompanyService;

    @RequestMapping(value = "/sCompany/byUserName/{username}",method = RequestMethod.GET)
    public ResponseEntity<SCompany> findSCompanyGgy(@PathVariable("username")String username){
        SCompany sCompany = sCompanyService.getOne(new QueryWrapper<SCompany>().lambda().eq(SCompany::getLegal, username));
        return ResponseEntity.ok(sCompany);
    }
    //查询所有公司及下面类型和商品
    @GetMapping("/companys")
    public ResponseEntity<List<SCompany>> findAllCom(){
        return ResponseEntity.ok(sCompanyService.findAllSCompany());
    }
    //手动添加公司
    @PostMapping("/company")
    public ResponseEntity<String> addCompany(@RequestBody SCompany company){
        String s = sCompanyService.addCompany(company);
        return ResponseEntity.ok(s);
    }
    //模糊查询
    @GetMapping("/company/{current}/{size}/{companyProvince}/{companyCity}/{companyArea}/{companyName}")
    public ResponseEntity<IPage<SCompany>> findLike(@PathVariable("current")int current, @PathVariable("size")int size, @PathVariable("companyProvince")String companyProvince,
                                                    @PathVariable("companyCity")String companyCity, @PathVariable("companyArea")String companyArea, @PathVariable("companyName")String companyName){
        return ResponseEntity.ok(sCompanyService.findLike(current,size,companyProvince,companyCity,companyArea,companyName));
    }
    @GetMapping("/company/{current}/{size}")
    public ResponseEntity<IPage<SCompany>> findCompany(@PathVariable("current")int current,@PathVariable("size")int size){
        return ResponseEntity.ok(sCompanyService.findCompany(current,size));
    }
}
